
public class HuffNode {

	public char c=0;
	public int size;
	public String path;
	public HuffNode left,right;
	
	public HuffNode(int s, HuffNode l, HuffNode r){
		this.size=s;
		left=huffCopy(l.c,l.size,l.right,l.left);
		right=huffCopy(r.c,r.size,r.right,r.left);
	}
	
	public HuffNode(char c,int s, HuffNode l, HuffNode r){
		this.size=s;
		this.c=c;
		this.left=l;
		this.right=r;
	}
	
	private HuffNode huffCopy(char c,int s, HuffNode l, HuffNode r){
		HuffNode ans=new HuffNode(c, s);
		ans.left=l;
		ans.right=r;
		return ans;
	}
	
	public String getNodesStrings(){
		return setNodesStrings(0,"");
	}
	
	private String setNodesStrings(int depth,String s){
		String ans="";
		if (left!=null){
			ans=left.setNodesStrings(depth+1,s+"0");
		}
		if (right!=null){
			ans=ans+right.setNodesStrings(depth+1,s+"1");
		}
		if (c>0){
			path=s;
			System.out.println("Set for "+this+"\tDepth is: "+depth+"\tCost is: "+depth*size);
			return ans+";"+this.c+","+this.path+","+depth*size;
		}
		return ans;
		
	}
	
	public HuffNode(int s){
		this.size=s;
	}
	
	public HuffNode(char c, int s){
		this.c=c;
		this.size=s;
	}
	
	public HuffNode(char c, String p){
		this.c=c;
		this.path=p;
	}
	
	public int compareTo(HuffNode other){
		return size-other.size;
	}
	
	public String toString(){
		char leftc=0,rightc=0;
		if (left!=null) leftc=left.c;
		if (right!=null) rightc=right.c;
		return "Char:\t"+c+"\tSize:"+size+"\tPath:"+path+"  \tLeft: "+leftc+"\tRight: "+rightc;
	}
	
}
